import Taro, { Component } from '@tarojs/taro'
import { View, Text ,Radio, RadioGroup, Label, Button, Image} from '@tarojs/components'
import './authlogin.css'
import app from '../../main.js';
import { AtButton } from 'taro-ui'
import { fail } from 'assert';
import { STATUS_CODES } from 'http';

export default class Index extends Component {

  config = {
    navigationBarTitleText: '授权登录'
  }

  constructor(){
    super(...arguments);
    this.state={
      test:{
        name:"joe",
        age:20
      }
    }
  }

  bindGetUserInfo(res) {
    console.log(res);
    var detail = res.detail;
    if (detail.errMsg == 'getUserInfo:ok') {
      var userInfo = JSON.parse(detail.rawData);
      var params = {
        nickname: userInfo.nickName,
        head_image: userInfo.avatarUrl,
        province: userInfo.province,
        city: userInfo.city
      }
      app.post('web/patient/setInfo', params, function(res) {
        if (res.data.status == 200) {
          if (app.isEmpty(res.data.result.phone)) {
            app.redirectTo('../authphone/authphone');
          } else {
            app.decidePage();
          }
        }
      });
    }
  }

  componentWillMount () {
    
  }

  componentDidMount () {}

  componentWillUnmount () { }

  componentDidShow () { }

  componentDidHide () { }
   
  render () {
    return (
      <View>
        <View className='top'>
          <View className='v_logo'>
            <Image className='logo' src={app.imageUri + 'img/logo_patient.png'} />
          </View>
          <View className='title'>爱眼医生</View>
        </View>
        <View className='content'>
          <View className='c_head'>登录后将获得以下权限</View>
          <View className='c_title'>
            <Image src={app.imageUri + 'img/check-box.png'} style='width:50rpx;height:50rpx;' />
            <View style='margin-left:20rpx;'>获得您的公开信息（昵称、头像等）</View>
          </View>
        </View>
        <View className='bottom'><Button className='b_btn' openType='getUserInfo' lang="zh_CN" onGetUserInfo={this.bindGetUserInfo}>授权登录</Button></View>
      </View>
    )
  }
}

